#ifndef WF_PLAYER_AUDIO_H
#define WF_PLAYER_AUDIO_H

#include <pthread.h>
#include "JniCallJava.h"
#include "Constant.h"
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>
#include "AVPacketQueue.h"
#include "AudioPlayStatus.h"

extern "C" {
#include <libavformat/avformat.h>
#include <libswresample/swresample.h>
};


class AudioPlay {
public:
    AVFormatContext *pAvFormatContext = nullptr;
    AVCodecContext *pAvCodecContext = nullptr;
    SwrContext *pSwrContext = nullptr;
    uint8_t *resampleOutBuffer = nullptr;
    JniCallJava *pJniCallJava = nullptr;
    int audioStreamIndex = -1;
    AVPacketQueue *pAVPacketQueue = nullptr;
    AudioPlayStatus *pAudioPlayStatus = nullptr;
public:
    AudioPlay(AVFormatContext *avFormatContext,
              JniCallJava *jniCallJava, int audioStreamIndex);

    ~AudioPlay();

    void play();

    void initOpenSLES();

    int resampleAudio();

    void analyzeStream(ThreadMode threadMode);

    void callOnError(ThreadMode threadMode, int errorCode, char *errorMsg);

    void release();
};


#endif
